/*** Eclipse Class Decompiler plugin, copyright (c) 2012 Chao Chen (cnfree2000@hotmail.com) ***/
package com.qihoo.gamecenter.sdk.login.plugin.accountBind.view;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Paint.FontMetrics;
import android.graphics.RectF;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.view.View.MeasureSpec;
import android.widget.TextView;
import com.qihoo.gamecenter.sdk.login.plugin.f.a;
import com.qihoo.gamecenter.sdk.login.plugin.h.f;

public class CustomTextView extends TextView {
    private static int a;
    private Paint b = new Paint();
    private RectF c = new RectF();
    private a d;
    private BitmapDrawable e;
    private Bitmap f;
    private int g;
    private String[] h;
    private boolean i = false;
    private float j;

    public CustomTextView(Context paramContext) {
        super(paramContext);
        this.b.setAntiAlias(true);
        this.b.setColor(-16777216);
        this.b.setTextSize(f.a(paramContext, 15.0F));
        this.d = a.a(paramContext);
        this.e = ((BitmapDrawable) this.d.a(1073741827));
        this.f = this.e.getBitmap();
        a = f.a(paramContext, 40.0F);
        this.j = f.a(getContext(), 3.0F);
        this.g = this.f.getHeight();
    }

    public void setCustomTextSize(int paramInt) {
        this.b.setTextSize(paramInt);
        invalidate();
    }

    protected void onDraw(Canvas paramCanvas) {
        Paint.FontMetrics localFontMetrics = this.b.getFontMetrics();
        float f1 = localFontMetrics.descent - localFontMetrics.ascent;
        float f2 = 0.0F;
        float f3 = f1;
        if ((getText() == null) || (this.h == null))
            return;
        this.c.set(0.0F, 0.0F, getWidth(), getMeasuredHeight() - this.g + getPaddingBottom());
        if (this.i) {
            this.b.setColor(Color.parseColor("#ededed"));
            paramCanvas.drawRoundRect(this.c, this.j, this.j, this.b);
            paramCanvas.drawBitmap(this.f, a, getMeasuredHeight() - this.g + getPaddingBottom(), this.b);
        }
        this.b.setColor(-16777216);
        for (String str : this.h) {
            paramCanvas.drawText(str, f2, f3, this.b);
            f3 += f1 + localFontMetrics.leading;
        }
    }

    private String[] a(String paramString, Paint paramPaint, float paramFloat) {
        int k = 0;
        if (paramString != null)
            k = paramString.length();
        float f1 = paramPaint.measureText(paramString);
        if (f1 <= paramFloat)
            return new String[] { paramString };
        int l = 0;
        int i1 = 1;
        int i2 = 0;
        int i3 = (int) Math.ceil(f1 / paramFloat);
        String[] arrayOfString = new String[i3];
        while (l < k) {
            if (paramPaint.measureText(paramString, l, i1) > paramFloat) {
                arrayOfString[(i2++)] = ((String) paramString.subSequence(l, i1 - 1));
                l = i1 - 1;
            }
            if (i1 == k) {
                arrayOfString[i2] = ((String) paramString.subSequence(l, i1));
                break;
            }
            ++i1;
        }
        return arrayOfString;
    }

    protected void onMeasure(int paramInt1, int paramInt2) {
        super.onMeasure(paramInt1, paramInt2);
        int k = View.MeasureSpec.getSize(paramInt1);
        int l = a(k) + this.g;
        setMeasuredDimension(k, l);
    }

    private int a(int paramInt) {
        String[] arrayOfString = a(getText().toString(), this.b, paramInt);
        this.h = arrayOfString;
        Paint.FontMetrics localFontMetrics = this.b.getFontMetrics();
        float f1 = localFontMetrics.descent - localFontMetrics.ascent;
        int k = (int) ((f1 + localFontMetrics.leading) * arrayOfString.length + 9.0F);
        return k;
    }

    public void setBackgroundDrawable(Drawable paramDrawable) {
        this.i = true;
    }
}